package com.ha.web.controller.system.intention.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ha.common.annotation.Log;
import com.ha.common.enums.BusinessType;
import com.ha.system.intention.domain.HaCustomerIntention;
import com.ha.system.intention.service.IHaCustomerIntentionService;
import com.ha.common.core.controller.BaseController;
import com.ha.common.core.domain.AjaxResult;
import com.ha.common.utils.poi.ExcelUtil;
import com.ha.common.core.page.TableDataInfo;

/**
 * 客户意向信息Controller
 */
@Controller
@RequestMapping("/intention/intention")
public class HaCustomerIntentionController extends BaseController {
    private String prefix = "intention/intention";

    @Autowired
    private IHaCustomerIntentionService haCustomerIntentionService;

    @RequiresPermissions("intention:intention:view")
    @GetMapping()
    public String intention() {
        return prefix + "/intention";
    }

    /**
     * 查询客户意向信息列表
     */
    @RequiresPermissions("intention:intention:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HaCustomerIntention haCustomerIntention) {
        startPage();
        List<HaCustomerIntention> list = haCustomerIntentionService.selectHaCustomerIntentionList(haCustomerIntention);
        return getDataTable(list);
    }

    /**
     * 导出客户意向信息列表
     */
    @RequiresPermissions("intention:intention:export")
    @Log(title = "客户意向信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HaCustomerIntention haCustomerIntention) {
        List<HaCustomerIntention> list = haCustomerIntentionService.selectHaCustomerIntentionList(haCustomerIntention);
        ExcelUtil<HaCustomerIntention> util = new ExcelUtil<HaCustomerIntention>(HaCustomerIntention.class);
        return util.exportExcel(list, "intention");
    }

    /**
     * 新增客户意向信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存客户意向信息
     */
    @RequiresPermissions("intention:intention:add")
    @Log(title = "客户意向信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HaCustomerIntention haCustomerIntention) {
        return toAjax(haCustomerIntentionService.insertHaCustomerIntention(haCustomerIntention));
    }

    /**
     * 修改客户意向信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        HaCustomerIntention haCustomerIntention = haCustomerIntentionService.selectHaCustomerIntentionById(id);
        mmap.put("haCustomerIntention", haCustomerIntention);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户意向信息
     */
    @RequiresPermissions("intention:intention:edit")
    @Log(title = "客户意向信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HaCustomerIntention haCustomerIntention) {
        return toAjax(haCustomerIntentionService.updateHaCustomerIntention(haCustomerIntention));
    }

    /**
     * 删除客户意向信息
     */
    @RequiresPermissions("intention:intention:remove")
    @Log(title = "客户意向信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(haCustomerIntentionService.deleteHaCustomerIntentionByIds(ids));
    }
}
